package com.example.rest;

import com.example.dto.UserDTO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author void
 * @date 2020/10/19 18:34
 * @desc 验证信息可以被继承,验证了两层继承ok
 */
@RestController
public class ValidateController {

    /**
     * get请求验证
     * @param dto
     */
    @GetMapping("/test1")
    public void test1(@Validated UserDTO dto){
        System.out.println(dto.getUserName());
    }

    /**
     * post请求验证
     * @param dto
     */
    @PostMapping("/test2")
    public void test2(@RequestBody @Validated UserDTO dto){
        System.out.println(dto.getUserName());
    }
}
